﻿@using KPIS.GERP.Models.ICM

@model PurchaseRequest

@{
    var MasterService = new KPIS.GERP.WEB.GIMS.IcmMasterService.IcmMasterServiceClient();
    var LookUpService = new KPIS.GERP.WEB.GIMS.IcmMasLookUpService.IcmMasLookUpServiceClient();
    var SysService = new KPIS.GERP.WEB.GIMS.SysMasterService.SysMasterServiceClient();

    var pcTypeSelectList = MasterService.SelectListPurchaseType(new MasPurchaseType { RecordStatus = "U" }, true);
    //var pcMethodSelectList = new KPIS.GERP.WEB.GIMS.IcmMasterService.IcmMasterServiceClient().SelectListPurchaseMethod(new MasPurchaseMethod { PcTypeId = , RecordStatus = "U" }, true);
    var prioritySelectList = LookUpService.MasLookUpSelectList(KPIS.GERP.Models.ICM.IcmMasLookUpType.LookUpType.Priority);
	var jobSiteSelectList = new KPIS.GERP.WEB.GIMS.JobsiteService.JobsiteServiceClient().LoadJobSiteSelectList(null, true);
    var yearTypeSelectList = SysService.SelectListYearType(null);
    var yearSelectList = SysService.SelectListGenerateRangeYear(15, 15, false);
    var durTypeSelectList = LookUpService.MasLookUpSelectList(KPIS.GERP.Models.ICM.IcmMasLookUpType.LookUpType.DurationType);
    var durCountSelectList = LookUpService.MasLookUpSelectList(KPIS.GERP.Models.ICM.IcmMasLookUpType.LookUpType.DurationCount);
    
    var newList = new List<SelectListItem>();
    var newItem = new SelectListItem() { Value = "", Text = "" };
    newList.Add(newItem);

    bool bEdit = ViewContext.RouteData.Values["action"].ToString().ToLower() == "edit";
}
 
@if (ViewContext.RouteData.Values["action"].ToString().ToLower() == "edit") { @Html.HiddenFor(model => model.PrId) }
@Html.HiddenFor(model => model.RecordStatus)
@Html.HiddenFor(model => model.Code)
@Html.HiddenFor(model => model.CreatedBy)
@Html.HiddenFor(model => model.CreatedWhen)
@Html.HiddenFor(model => model.UpdatedBy)
@Html.HiddenFor(model => model.UpdatedWhen)

<div class="widget-box" >
	<div class="widget-header header-color-blue2">
		<h4 class="lighter smaller">ข้อมูลหลัก</h4>
	</div>
	<div class="widget-body">
		<div class="widget-body-inner">
			<div class="widget-main">
                @if (Model != null && Model.PrId != 0)
                {
                    <div class="control-group">
                        <div class="control-label" style="margin-right: 25px;">
                            @(Model.PcTypeId == 1 ? "ใบขอซื้อ" : "ใบขอจ้าง")
                        </div>
                        <div style="margin-top: 5px !important;">
                            @* ใส่ชื่อให้พารามิเตอร์ที่จะส่ง ให้ตรงกับชื่อที่จะรับใน Controller ในที่นี้ชื่อ id ไม่อย่างนั้นจะเรียกหาไม่เจอ *@
                            @Html.ActionLink(" รายงานใบขอซื้อ/ขอจ้าง", "ReportPurchaseRequest", new {id = Model.PrId}, new {@class = "btn button-standard-width btn-small btn-blue icon-file bigger-120", role = "button"})
                        </div>
                    </div>
                    <div class="control-group">
                        <div class="control-label">
                            @*@Html.DisplayNameFor(model => model.Code)*@เลขขอซื้อ/จ้าง
                        </div>
                        <div class="controls-detail" style="margin-top: 5px !important; font-weight: bold;">
                            @Html.DisplayFor(model => model.Code)
                        </div>
                    </div>
                }
				<div class="control-group">
					<div class="control-label">
						@Html.DisplayNameFor(model => model.MasPurchaseType.PcTypeName)
					</div>
					<div class="controls">
						@Html.DropDownListFor(m => m.PcTypeId, pcTypeSelectList
                            , new Dictionary<string, object>{{"class","chzn-select"}, {"data-placeholder", "เลือกประเภทการจัดหา"}, {"id", "ddlPcTypeId"}})
						
						@Html.ValidationMessageFor(model => model.PcTypeId)
					</div>
				</div>

                <div class="control-group">
					<div class="control-label">                        @Html.DisplayNameFor(model => model.PcMethodId)
					</div>
					<div class="controls">
						@Html.DropDownListFor(m => m.PcMethodId
                            , (bEdit ? MasterService.SelectListPurchaseMethod(new KPIS.GERP.Models.ICM.MasPurchaseMethod() { PcTypeId = Model.PcTypeId.GetValueOrDefault(-1)
                                , RecordStatus = "!" + KPIS.GERP.Models.SYS.RecordStatus.DeletedStatus }, true).ToList() : newList)
                            , new Dictionary<string, object>{{"class","chzn-select"}, {"data-placeholder", "เลือกวิธีการซื้อ/จ้าง"}, {"id", "ddlPcMethodId"}})
						
						@Html.ValidationMessageFor(model => model.PcTypeId)
					</div>
				</div>

				<div class="control-group">
					<div class="control-label">
						@Resources.GenerallyLocalization.Priority 
					</div>
					<div class="controls">
						@{ int i = 0; }
						@foreach (var prioritySl in prioritySelectList)
						{ 
							<label style="float: left">
								<input name="PriorityId" type="radio" 
									value="@prioritySl.Value" 
									@((i == 0 && Model == null) || (Model != null && prioritySl.Value == Model.PriorityId.ToString())? 
										"checked=\"checked\"" : string.Empty)/>
								<span class="lbl"> @prioritySl.Text </span> &nbsp;&nbsp;&nbsp;
							</label>
							i++;
						}
						 
						@Html.ValidationMessageFor(model => model.PriorityId)
					</div>            
				</div>
				<hr />
				
				@*<div class="control-group">
					<div class="control-label">
						@Html.DisplayNameFor(model => model.RequestJobSite.Name)
					</div>
					<div class="controls">
						@Html.DropDownListFor(m => m.RequestJobSiteId, jobSiteSelectList, new Dictionary<string, object>{{"class","chzn-select"}, {"data-placeholder", "เลือกหน่วยงาน"}})
						 
						@Html.ValidationMessageFor(model => model.RequestJobSiteId)
					</div>
				</div>*@

				<div class="control-group">
					<div class="control-label">
						@Html.DisplayNameFor(model => model.YearType.YearTypeName)
					</div>
					<div class="controls">
						@{ i = 0; }
						@foreach (var data in yearTypeSelectList)
						{ 
							<label style="float: left">
								<input name="YearTypeId" type="radio" value="@data.Value" 
									@((i == 0 && Model == null) || (Model != null &&
										KPIS.GERP.Models.Class.CompareUtility.IsObjectToStringEqual(data.Value, Model.YearTypeId)) ? "checked=\"checked\"" : string.Empty) />
								<span class="lbl"> @data.Text </span>&nbsp;&nbsp;&nbsp;
							</label>
							i++;
						}

						@Html.ValidationMessageFor(model => model.YearTypeId)
					</div>            
				</div>
				
				<div class="control-group">
					<div class="control-label">
						@Html.DisplayNameFor(model => model.BgYear)
					</div>
					<div class="controls">
						@{
							var currentYear = yearSelectList.FirstOrDefault(o => KPIS.GERP.Models.Class.CompareUtility.IsObjectToStringEqual(o.Value, KPIS.GERP.Models.Class.Utility.BuddishYear));
							if(currentYear != null ) { currentYear.Selected = true; }
						}
						@Html.DropDownListFor(m => m.BgYear, yearSelectList, new Dictionary<string, object>{{"class","chzn-select"}, {"data-placeholder", "เลือกปีงบประมาณ"}})

						@Html.ValidationMessageFor(model => model.BgYear)
					</div>            
				</div>
				
				<div class="control-group">
					<div class="control-label">
						@Html.DisplayNameFor(model => model.PurchaseDate)
					</div>
					<div class="controls">
						@Html.EditorFor(model => model.PurchaseDate, new {placeholder = "วันที่ทำรายการ"} )

						@Html.ValidationMessageFor(model => model.PurchaseDate)
					</div>            
				</div>
				
				<div class="control-group">
					<div class="control-label">
						@Html.DisplayNameFor(model => model.Name)
					</div>
					<div class="controls">
						@Html.TextBoxFor(model => model.Name, new {placeholder = "ใส่ชื่อเรื่อง"})

						@Html.ValidationMessageFor(model => model.Name)
					</div>            
				</div>

				<div class="control-group">
					<div class="control-label">
						@Html.DisplayNameFor(model => model.Reason)
					</div>
					<div class="controls">
						@Html.TextAreaFor(model => model.Reason, new { rows = 10, @class = "span6", placeholder = "ใส่เหตุผลของการจัดหา" })

						@Html.ValidationMessageFor(model => model.Reason)
					</div>            
				</div> 
				
				<div class="control-group">
					<div class="control-label">
						วันที่ต้องการใช้งาน
					</div>
					<div class="controls"> 
						@{
							var durType12 = durTypeSelectList.FirstOrDefault(o => o.Value == "12");
							var durType13 = durTypeSelectList.FirstOrDefault(o => o.Value == "13");
						}
					    <table>
					        <tr>
					            <td>

					                <div id="durType1">
					                    <label style="float:left; width:20px">
					                        @Html.RadioButtonFor(m => m.DurTypeId, 12, new { id = "durType1radio" })
					                        <span class="lbl"> @(durType12 != null ? durType12.Text : string.Empty) </span>&nbsp;&nbsp;&nbsp;
					                    </label>
					                    @Html.TextBoxFor(m => m.RequireDuration, new { style = "width:60px" })
					                    @Html.DropDownListFor(m => m.DurTypeId, durTypeSelectList, new { style = "width:100px" })
					                    @Html.DropDownListFor(m => m.DurCountId, durCountSelectList, new { style = "width:200px" })
					                </div> 
					            </td>
					        </tr>
                            <tr>
					            <td><div id="durType2" style=" padding-left:0px;">
					                    <label style="float: left; width: 20px">
					                        @Html.RadioButtonFor(m => m.DurTypeId, 13, new { id = "durType2radio" })
					                        <span class="lbl"> @(durType13 != null ? durType13.Text : string.Empty) </span>&nbsp;&nbsp;&nbsp;
					                    </label>
					                    @Html.EditorFor(m => m.RequireDate)
					                </div>
                                </td>
					        </tr>
					    </table>
					</div>
				</div> 
			</div>
		</div>
	</div>
</div>